package com.cct.digitalarchapi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.cct.digitalarchapi.common.CommonUtil;
import com.cct.digitalarchapi.common.Response;
import com.cct.digitalarchapi.pojo.ArchCategory;
import com.cct.digitalarchapi.pojo.ArchDeptCategory;
import com.cct.digitalarchapi.service.ArchCategoryService;
import com.cct.digitalarchapi.service.ArchDeptCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @FileName ArchDeptCategoryController
 * @Description 档案控制器
 * @Author Created by chenmingzhe
 * @Date 2023/11/19
 **/
@RestController
@RequestMapping(value = "/archDeptCategory")
public class ArchDeptCategoryController {
    @Autowired
    private ArchDeptCategoryService archDeptCategoryService;
    @Autowired
    private CommonUtil commonUtil;
    /**
     *获取所有的部门档案分类
     */
    @RequestMapping(value = "/getAllDeptCategory",method = RequestMethod.POST)
    public Response getAllCategory(@RequestBody JSONObject obj){
        int pageNum=obj.getInteger("pageNum");
        int pageSize=obj.getInteger("pageSize");
        //为空时查所有,根据档案分类名字查询
        String archCateName=obj.getString("archCateName");
        //为空时查所有,根据部门分类名字查询
        String archDeptName=obj.getString("archDeptName");
        return  archDeptCategoryService.getAllDeptCategory(pageNum,pageSize,archCateName,archDeptName);
    }
    /**
     * 新增部门档案分类
     */
    @RequestMapping(value = "/addDeptCategory",method = RequestMethod.POST)
    public Response addCategory(@RequestBody ArchDeptCategory archDeptCategory){
        commonUtil.recordOperateLog("新增部门名称为"+archDeptCategory.getArchDeptName()+",档案分类名称为"+archDeptCategory.getArchCateName()+"的部门档案分类");
        return  archDeptCategoryService.addDeptCategory(archDeptCategory);
    }
    /**
     *删除一个部门档案分类
     */
    @RequestMapping(value = "/deleteDeptCategory",method = RequestMethod.POST)
    public Response deleteCategory(@RequestBody JSONObject obj){
        int archDeptCatId = obj.getInteger("archDeptCatId");
        commonUtil.recordOperateLog("删除部门档案分类Id为"+archDeptCatId+"的部门档案分类");
        return  archDeptCategoryService.deleteDeptCategory(archDeptCatId);
    }
    /**
    *更新一个部门档案分类  archDeptClassType,notes;
    */
    @RequestMapping(value = "/updateDeptCategory",method = RequestMethod.POST)
    public Response updateDeptCategory(@RequestBody ArchDeptCategory archDeptCategory){
        commonUtil.recordOperateLog("更新了部门档案分类Id为"+ archDeptCategory.getArchDeptCatId()+"的部门档案分类");
        return  archDeptCategoryService.updateDeptCategory(archDeptCategory);
    }
    /**
     *获取档案分类下的档案部门编码
     */
    @RequestMapping(value = "/getDeptWithCate",method = RequestMethod.POST)
    public Response getDeptWithCate(){
        return  archDeptCategoryService.getDeptWithCate();
    }

}
